home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5288 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Where Can I Find Standard C Library S
  5. Date: 9 Feb 1996 17:13:44 GMT
  6. Organization: OpenVision
  7. Message-ID: <4ffvc8$i02@spanky.pls.ov.com>
  8. References: <3119E6D9.60FD@cmt.lpr.mail.carel.fi>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 60FD@cmt.lpr.mail.carel.fi, Ari Lukumies <aril@cmt.lpr.mail.carel.fi> writes:
  13. >Fletcher.Glenn@ov.com wrote:
  14. >> 
  15. >> 
  16. >> Whoops! for strcpy:
  17. >> 
  18. >> char *strcpy(char *destination, char *source)
  19. >> {
  20. >>     char *retval;
  21. >> 
  22. >>     retval = destination;
  23. >>     while((*destination++ = *source++) != '\0');
  24. >>     return(retval);
  25. >> }
  26. >>                         Fletcher.Glenn@ov.com
  27. >
  28. >.... And you wonder why printf("%s\n", strcpy(tmp, "thingyam")); may not give correct 
  29. >results using your strcpy version... Try this for size:
  30. >
  31. >    char *strcpy(char *destination, char *source)
  32. >    {
  33. >        char *retval = destination;
  34. >
  35. >        do
  36. >            *destination = *source++;
  37. >        while (*destination++ != '\0');
  38. >        return retval;
  39. >    }
  40. >
  41. >This will also copy the nul-terminator. :)
  42. >
  43. >Later,
  44. > AriL
  45. >-- 
  46. >All my opinions are mine and mine alone.
  47.  
  48.  
  49. Actually, you'll notice that mine does copy the null terminator.  Note that
  50. the results of the assignment is used in the test.  See K+R2 Pg 105.  (I
  51. did see the smiley.) :-)
  52.  
  53.             Fletcher.Glenn@ov.com
  54.  
  55.  
  56.